% This subroutine calculates a random white noise.
% It is used in the AR1 process to evaluate red noise.
% for an AR1 autocorrelation of data with fixed sampling step d.

%In case of a constant sampling step, a=rho^(1/d) (with 0<a<1)
%                                  
%                                         _n             _n
% then, according to Mudelsee 2002,  rho= \ (x(i)x(i-1)/ \x(i-1)^2
%                                         /              /
%                                         i=2            i=2
%
%
%
%
%Inputs : 
%data1 = 1 column array with measures resampled with a constant sampling step.
%
%Doroth�e Husson, November 2012

nrho=length(data1);
rho=0;
sommesup=0;
sommeinf=0;
for i=2:nrho
    j=i-1;
    sommesup=sommesup+(data1(i)*data1(j));
    sommeinf=sommeinf+((data1(j))^2);
end
rho=sommesup/sommeinf;